package com.hpin.fansea.my;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.hpin.fansea.R;
import com.hpin.fansea.base.BaseActivity;
import com.hpin.fansea.utils.Constant;
import com.hpin.fansea.widget.CircleImageView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;

/**
 *
 * 我的信息展示页面
 * Created by Aaron on 15/9/18.
 */
public class MyInfoActivity extends BaseActivity {

    private DisplayImageOptions options;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_my_info);

        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.icon_headpic_default)
                .showImageForEmptyUri(R.mipmap.icon_headpic_default)
                .showImageOnFail(R.mipmap.icon_headpic_default)
                .resetViewBeforeLoading(true)
                .cacheOnDisk(true).cacheInMemory(true)
                .cacheOnDisc(true).imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .considerExifParams(true)
                .displayer(new SimpleBitmapDisplayer()).build();

        initWidget();

    }

    private void initWidget() {

        ImageView iv_left = (ImageView) findViewById(R.id.iv_left);
        TextView tv_title = (TextView) findViewById(R.id.tv_title);
        TextView tv_right = (TextView) findViewById(R.id.tv_right);

        tv_title.setText(getResources().getString(R.string.my_info));
        tv_right.setText(getResources().getString(R.string.my_modify));

        iv_left.setOnClickListener(this);
        tv_right.setOnClickListener(this);

        setHeadInfo();

        TextView tv_phone = (TextView) findViewById(R.id.tv_phone);
        TextView tv_mail = (TextView) findViewById(R.id.tv_mail);
        TextView tv_realname = (TextView) findViewById(R.id.tv_realname);
        TextView user_community = (TextView) findViewById(R.id.user_community);
        TextView tv_birthday = (TextView) findViewById(R.id.tv_birthday);

        RadioButton rb_male_button = (RadioButton) findViewById(R.id.radioMale);
        RadioButton rb_female_button = (RadioButton) findViewById(R.id.radioFemale);

        tv_phone.setText(sp.getString(Constant.mobile, ""));
        tv_mail.setText(sp.getString(Constant.email, ""));
        tv_realname.setText(sp.getString(Constant.nickname, ""));
        user_community.setText(sp.getString(Constant.communityName, ""));
        tv_birthday.setText(sp.getString(Constant.birthday, ""));

        if ( Constant.SEX_FREMALE.equals(sp.getString(Constant.gender, ""))) {

            rb_female_button.setSelected(true);
            rb_male_button.setSelected(false);

        }else {

            rb_female_button.setSelected(false);
            rb_male_button.setSelected(true);

        }

    }

    private void setHeadInfo() {

        // 头像
        CircleImageView head_img = (CircleImageView) findViewById(R.id.head_img);

        ImageLoader.getInstance().displayImage(sp.getString(Constant.headPic, ""), head_img, options);

        // 认证的图片
        ImageView my_auth = (ImageView) findViewById(R.id.my_auth);
        TextView tv_username = (TextView) findViewById(R.id.tv_username);
        TextView tv_community = (TextView) findViewById(R.id.tv_community);

        if (Constant.AUTH_USER.equals(sp.getString(Constant.status, "")) || Constant.AUTH_PASSED.equals(sp.getString(Constant.status, "")))
            my_auth.setVisibility(View.VISIBLE);
        else
            my_auth.setVisibility(View.INVISIBLE);

        tv_username.setText(sp.getString(Constant.nickname, ""));
        tv_community.setText(sp.getString(Constant.communityName, ""));

    }

    @Override
    public void widgetClick(View v) {

        switch (v.getId()) {

            case R.id.iv_left:

                finish();

                break;

            case R.id.tv_right:// 修改

                Intent mIntent = new Intent(this, ModifyInfoActivity.class);
                startActivity(mIntent);

                break;

        }

    }
}
